package com.xcc.observerpattern.demo1;

/**
 * @Description: ForecastDisplay
 * @Author: xiechuang
 * @Date: 2022/6/28
 */
public class ForecastDisplay implements Observer, DisplayElement {

    // 温度值
    private float temperature;
    // 湿度值
    private float humidity;
    // 气压值
    private float pressure;

    private Subject weatherData;

    public ForecastDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println("ForecastDisplay 当前温度：" + temperature + "，湿度：" + humidity + "，气压值：" + pressure);
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        display();
    }

}
